package org.gourpg.entity.permission;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Objects;

/**
 * 权限配置实体
 */
@Entity
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Table(name = "permission_detail")
public class PermissionDetail {
    /**
     * 权限ID，权限的主键
     */
    @Id
    private Long powerId;

    /**
     * 权限名称
     */
    private String powerName;

    /**
     * 权限类型（管理、维护、查看）字典：POWER_TYPE
     */
    private String powerType;

    /**
     * 权限说明
     */
    private String powerRemark;

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        PermissionDetail that = (PermissionDetail) o;
        return getPowerId() != null && Objects.equals(getPowerId(), that.getPowerId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
